﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VipSys.DataLayer;
using VipSys.SystemEntity;
using VipSys.Common.Library;

namespace VipSys
{
    public partial class ChangePwd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnOk_Click(object sender, EventArgs e)
        {
            SysAccount sysAccount = Session["SysAccount"] as SysAccount;
            if (sysAccount == null)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('登录超时，请重新登录!')</script>");
                return;
            }
            if (txtOldPwd.Text.Trim() != sysAccount.Password)
            {
                this.RegisterStartupScript("错误信息", "<script>alert('原始密码错误!')</script>");
                return;
            }

            if (this.txtAffirmPwd.Text.Trim() != txtNewPwd.Text.Trim())
            {
                this.RegisterStartupScript("错误信息", "<script>alert('两次输入密码不一致!')</script>");
                return;
            }
            sysAccount.Password=txtNewPwd.Text.Trim();
            if (sysAccount.RoleType == SystemData.RoleType.USER)
            {
                User user = new User();
                user.ID = sysAccount.ID;
                UserAccess.Instance.GetUser(user, ref user);
                user.PassWord = txtNewPwd.Text.Trim();
                short shRet= UserAccess.Instance.Edit(user);
                if (shRet != SystemData.ReturnValue.OK)
                {
                    this.RegisterStartupScript("错误信息", "<script>alert('密码修改失败!')</script>");
                    return;
                }
            }
            else
            {
                Employee user = new Employee();
                user.ID = sysAccount.ID;
                EmployeeAccess.Instance.GetEmployee(user, ref user);
                user.PassWord = txtNewPwd.Text.Trim();
                short shRet = EmployeeAccess.Instance.Edit(user);
                if (shRet != SystemData.ReturnValue.OK)
                {
                    this.RegisterStartupScript("错误信息", "<script>alert('密码修改失败!')</script>");
                    return;
                }
            }
            this.RegisterStartupScript("错误信息", "<script>alert('密码修改成功!')</script>");

        }
    }
}